package com.wgt.util;


import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.util.ArrayList;
import java.util.List;

/**
 * 处理javabean验证处理器
 * @author wgt
 * @date 2018/1/4
 * @project new-start-blog
 */
public class ConstraintViolationExceptionHandler {
    /**
     * 批量获取异常信息
     * @param e
     * @return
     */
    public static String getMessage(ConstraintViolationException e){
        List<String> messages = new ArrayList<>();
        for (ConstraintViolation<?> constraintViolation : e.getConstraintViolations()){
            messages.add(constraintViolation.getMessage());
        }
        String msg = StringUtils.join(messages.toArray(),";");
        return msg;
    }
}
